<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('质量检查列表')" />
    <th:block th:include="include :: jq-viewer-css" />
    <style type="text/css">
        #imageBox img{width:100%;display:none}
        body{
            border-style: solid;
            border-width: 1px;
        }
    </style>
</head>
<!--全局js -->
<script th:src="@{/js/commonTool.js}"></script>

<body class="gray-bg" unload="if(bFlag){window.returnValue='OK';}">
<script th:inline="javascript">
    //遮罩层
    $.modal.loading("数据加载中......");
</script>
<!-- 影像区域 -->
<div class="col-md-12" style="padding-right:5px;">
    <div class="box">
        <div class="box-header">
            <h3 class="box-title">影像信息</h3>
        </div>
        <div class="box-main">
            <div id="imageBox" style="height:520px;">
            </div>
        </div>
    </div>
</div>

<!--监控信息基本信息区域  -->
<div style="position: absolute;width: 100%;left: 15px;bottom: 30px">
    <div th:include="oms/paeaAuAuditItem/auBatchItemDetail :: auBatchItemDetail"></div>
</div>

<!-- 操作按钮 -->
<div id="btnsDiv" align="center" style="bottom: 1px;position: absolute;width: 99%">
    <input type=button class="btn btn-sm btn-primary" style='width:85px' id="createErrBT" value='创建差错' onclick="createError();">
    <input type=button class="btn btn-sm btn-primary" style='width:65px' value='复核' onclick="reAuditConfirm()">
    <input type=button class="btn btn-sm btn-primary" style='width:65px' value='流水查询' onclick="_queryTrade()">
    <input type=button class="btn btn-sm btn-primary" style='width:65px' value='流水详情' onclick="queryAuItemTrade();">
    <input type=button class="btn btn-sm btn-primary" style='width:90px' value='查看柜员影像' onclick="manualInputDetail();">
    <input type=button class="btn btn-sm btn-primary" style='width:65px' value='关闭窗口' onclick="window.close()">
</div>
<input type="hidden" name="batchId" id="batchId" th:value="${batchId}">
<input type="hidden" name="orgIdInput" id="orgIdInput" th:value="${orgIdInput}">
<input type="hidden" name="batchTypeInput" id="batchTypeInput" th:value="${batchTypeInput}">
<input type="hidden" name="stateInput" id="stateInput" th:value="${stateInput}">
<input type="hidden" name="beginDateInput" id="beginDateInput" th:value="${beginDateInput}">
<input type="hidden" name="endDateInput" id="endDateInput" th:value="${endDateInput}">
<input type="hidden" name="auditorIdInput" id="auditorIdInput" th:value="${auditorIdInput}">
<th:block th:include="include :: footer" />
<th:block th:include="include :: jq-viewer-js" />
<th:block th:include="include :: keyMoney-js" />
<!-- 初始化影像 -->
<script th:inline="javascript">
    var bFlag = false;
    var batchId = $("#batchId").val();
    var beginDateInput = $("beginDateInput").val();
    var endDateInput = $("endDateInput").val();
    var orgIdInput = $("orgIdInput").val();
    var auditorIdInput = $("auditorIdInput").val();
    var stateInput = $("stateInput").val();
    var batchTypeInput = $("batchTypeInput").val();
    $(function () {
    //初始化影像区域
    initImageArea();
    //初始化影像
    initImage();
    //初始化监控数据及更新影像
    initInfo();
    })
    //初始化影像显示
    function initImageArea() {
    //加载一张默认图片
        $('#imageBox').append('<img name= "img'+'demo'+'" id="imgArea" src="" alt="示例图片">');
        $('#imageBox').viewer({inline:true}).viewer('update');
    }
    //初始化影像
    function initImage() {
        var imgUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1584958911886&di=47b6a313b01424ad2593609115dbd145&imgtype=0&src=http%3A%2F%2Fbbsfiles.vivo.com.cn%2Fvivobbs%2Fattachment%2Fforum%2F201507%2F31%2F161843qkvv4oq21nrvtjui.jpg";
        $('#imgArea').attr("src", imgUrl);
        $('#imageBox').viewer({inline:true}).viewer('update');
    }
    //初始化监控数据及更新影像
    function initInfo(){
        var data = {"batchId": batchId};
        var url = ctx+"oms/paeaAuAuditItem/querySdiImagesWithTrade";
        $.operate.post(url,data,function(result){
            var splitCharLevel1 = "Level@@@@@";
            var splitCharLevel2 = "@@@";
            if(result.code==web_status.SUCCESS){
                var itemData = (result.taskString).split(splitCharLevel1);
                var itemInfoDetail = itemData[0];
                var itemInfoImg = itemData[1];
                var itemInfoPoint = itemData[2];
                var paeaAutypeName = itemInfoPoint.substring(itemInfoPoint.indexOf("^")+1,itemInfoPoint.length);
                document.getElementById("auTypeName").value= paeaAutypeName;
                //刷新监控基本信息
                CommonTool.replaceExistingWithNewHtml(itemInfoDetail.split("]"));
                //刷新监控影像信息
                refreshAuditImg(itemInfoImg.split(splitCharLevel2));
                $.modal.closeLoading();
            } else {
                $.modal.msgError(result.msg);
            }
        });
    }
    //刷新监控影像
    function refreshAuditImg(itemForImgArray){
        sdiImageList = itemForImgArray;
        $('#imageBox').empty();
        $.each(sdiImageList, function(index, sdiImage) {
            var imageUrl = sdiImage;
            $('#imageBox').append('<img name= "img'+index+'" src="'+imageUrl+'" alt="影像">');
        });
        $('#imageBox').viewer({inline:true}).viewer('update');
    }
</script>
<!--其他function -->
<script th:inline="javascript">
    //创建督办
    function createError() {
        var auditItemId = $("#itemId").val();
        var trDate = $("#trDate").val();
        var brCode = $("#brCode").val();
        var trTelr = $("#trTelr").val();
        var txnSeq = $("#txnSeq").val();
        var auTypeId = $("#auTypeId").val();
        var tradeId = $("#dsTradeId").val();
        var batchId = $("#batchId").val();
        var errSource = 400;//差错类型  PaeaErrorSource.S重点监控.getValue()
        var vchFlag = 1;//有流水的标识
        var manFlag = 0;//人工创建标识
        var url = ctx + "oms/paeaAuAuditItem/isReAudit";
        var data = {"id": auditItemId, "trDate" : trDate};
        $.operate.post(url, data, function (result) {
            if (result.code == web_status.SUCCESS) {
                //创建差错
                registerErrorPre(errSource, vchFlag, manFlag,trDate, brCode, trTelr, txnSeq, tradeId, auTypeId, batchId,auditItemId);
            } else {
                $.modal.msgError(result.msg);
                return false;
            }
        })
    }

    //跳转创建督办页面，调用创建督办页面
    function registerErrorPre(errSource,vchFlag,manFlag,trDate,orgId,tellerId,vchNo,tradeId,auTypeId,batchId,auditItemId){
        var url =  ctx  + 'oms/paeaAuAuditItem/registerErrorPre?errSource='+errSource+'&vchFlag='+vchFlag+'&manFlag='+manFlag+'&trDate='+trDate+'&orgId='+orgId+'&tellerId='+tellerId+'&vchNo='+vchNo+'&tradeId='+tradeId+'&auTypeId='+auTypeId+'&auditItemId='+auditItemId;
        var flag = window.showModalDialog(url,"查询督办","dialogWidth=1000px; dialogHeight=500px; help=yes; status=yes; scroll=yes; resizable=yes;");
        if(flag){
            afterRegisterErr(auditItemId,trDate);
        }
    }

    //创建督办后的回调函数
    function afterRegisterErr(auditItemId,trDate){
        var url = ctx + "oms/paeaAuAuditItem/registerErrorWithFlow";
        var data = {"id": auditItemId, "batchId": batchId, "trDate": trDate};
        $.operate.post(url,data,function(result){
            if (result.code == web_status.SUCCESS) {
                var reflag = result.reflag;
                if(reflag == "1"){
                    bFlag = true;
                    $.modal.msgSuccess("复核成功，切换下一笔流水");
                    //获取该批次的下一笔流水
                    initInfo();
                    window.returnValue = "OK";
                }else if(reflag == "2"){
                    $.modal.confirm("该批次已复核完毕！是否进入下一批次？",function(){
                        var reUrl = ctx + "oms/paeaAuAuditItem/toNextReAuditItemInfo";
                        var reData = {"beginDate": beginDateInput, "endDate": endDateInput, "state": stateInput, "orgId": orgIdInput, "auditorId": auditorIdInput, "batchType":batchTypeInput};
                        $.operate.post(reUrl, reData, function (result2) {
                            if (result2.code == web_status.SUCCESS) {
                                batchId = result2.nextBatchId;
                                bFlag = true;
                                $.modal.msgSuccess("复核成功，切换下一笔流水");
                                //获取该批次的下一笔流水
                                initInfo();
                                window.returnValue = "OK";
                            } else {
                                $.modal.confirm("已无符合条件的重点监督批次，是否关闭窗口，重新查询且选择监督批次？",function(){
                                window.returnValue = "OK";
                                window.close();
                                })
                            }
                        })
                    })
                }
            } else {
                $.modal.msgError(result.msg);
            }
        });
    }

    //查看流水详情
    function queryAuItemTrade() {
        var tradeId = $("#dsTradeId").val();
        var url = ctx + "paea/paeaDsTrade/detail/"+tradeId;
        window.showModalDialog(url,"查看流水","dialogWidth=1000px; dialogHeight=500px; help=yes; status=yes; scroll=yes; resizable=yes;");
    }
    //流水查询
    function _queryTrade(){
        var url = ctx + "paea/paeaDsTrade";
        window.showModalDialog(url, "", "dialogWidth=1000px; dialogHeight=600px; help=no; status=no; scroll=yes; resizable=no;");
    }
    //查看柜员影像
    function manualInputDetail() {
        if(window.showModalDialog)
        {
            var x = screen.availWidth;
            var y = screen.availHeight;
            var trTelr = $("#trTelr").val();
            var brCode = $("#brCode").val();
            var trDate = $("#trDate").val();
            var url = ctx + "oms/paeaAuAuditItem/querySdiPaeaArcId";
            var data = {"trDate": trDate, "orgCode": brCode, "tellerCode": trTelr};
            $.operate.post(url, data, function (result) {
                if (result.code == web_status.SUCCESS) {
                    var arcId = result.arcId;
                    var obj = window.showModalDialog('/sdi/input/manualInputDetail/' + arcId, window, 'dialogWidth:' + x + 'px;dialogHeight:' + y + 'px;center:yes;help:yes;resizable:no;status:yes;scroll:no;');
                } else {
                    $.modal.msgError(result.msg);
                }
            })
        }
    }

    //复核确认
    function reAuditConfirm(){
        var auditItemId = $("#itemId").val();
        var trDate = $("#trDate").val();
        var url = ctx + "oms/paeaAuAuditItem/reAuditConfirm";
        var data = {"id": auditItemId, "batchId": batchId, "trDate": trDate};
        $.operate.post(url, data, function (result) {
            if (result.code == web_status.SUCCESS) {
                var returnFlag = result.returnFlag;
                if(returnFlag == "1"){
                    bFlag = true;
                    $.modal.msgSuccess("复核成功，切换下一笔流水");
                    //获取该批次的下一笔流水
                    initInfo();
                    window.returnValue = "OK";
                }else if(returnFlag == "2"){
                    $.modal.confirm("该批次已复核完毕！是否进入下一批次？",function(){
                        var reUrl = ctx + "oms/paeaAuAuditItem/toNextReAuditItemInfo";
                        var reData = {"beginDate": beginDateInput, "endDate": endDateInput, "state": stateInput, "orgId": orgIdInput, "auditorId": auditorIdInput, "batchType":batchTypeInput};
                        $.operate.post(reUrl, reData, function (result2) {
                            if (result2.code == web_status.SUCCESS) {
                                batchId = result2.nextBatchId;
                                bFlag = true;
                                $.modal.msgSuccess("复核成功，切换下一笔流水");
                                //获取该批次的下一笔流水
                                initInfo();
                                window.returnValue = "OK";
                            } else {
                                $.modal.confirm("已无符合条件的重点监督批次，是否关闭窗口，重新查询且选择监督批次？",function(){
                                    window.returnValue = "OK";
                                    window.close();
                                })
                            }
                        })
                    })
                }
            } else {
                $.modal.msgError(result.msg);
            }
        })
    }

    //判断是否已复核
    function isAudit(){
        var auditItemId = $("#itemId").val();
        var trDate = $("#trDate").val();
        var url = ctx + "oms/paeaAuAuditItem/isReAudit";
        var data = {"id": auditItemId, "trDate" : trDate};
        $.operate.post(url, data, function (result) {
            if (result.code == web_status.SUCCESS) {
                //无处理
                return true;
            } else {
                $.modal.msgError(result.msg);
                return false;
            }
        })
    }
</script>
</body>
</html>
